package winOrDie.graphicsInterface.maps;

import org.eclipse.swt.graphics.GC;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Display;

import winOrDie.graphics.maps.Map_Board;
import winOrDie.graphics.maps.Map_Cell;
import winOrDie.graphics.maps.Map_Colors;
import winOrDie.graphics.maps.Map_Cell.Map_Cell_Type;


public class Map_Designer {

	
	/**
	 * This public static method returns {@link RGB} color from {@link Map_Cell}
	 * @deprecated
	 * @param mapCell
	 * @return {@link RGB}
	 * @throws Exception
	 */
	public static RGB get_RGB_From_Cell(Map_Cell mapCell) throws Exception
	{
		final int brush_type = mapCell.getType();
		RGB rgb = null;
		
		switch (brush_type) {
		case Map_Cell_Type.Corridor:
			rgb = Map_Colors.rgb_Corridor;
			break;
		case Map_Cell_Type.Wall:
			rgb = Map_Colors.rgb_Wall;
			break;						
		case Map_Cell_Type.Pirates_Room:
			rgb = Map_Colors.rgb_Pirates_Room;
			break;
		case Map_Cell_Type.Tower:
			rgb = Map_Colors.rgb_Tower;
			break;
		case Map_Cell_Type.Tower_Door:
			rgb = Map_Colors.rgb_Tower_Door;
			break;
		case Map_Cell_Type.Exit:
			rgb = Map_Colors.rgb_Exit;
			break;
		default:
			Exception exception = new Exception("Unknow cell type.");
			throw exception;
		}
		return rgb;
	}
	
	/**
	 * This public static method returns a {@link Image} object from {@link Map_Board}
	 * @deprecated
	 * @param mapBoard
	 * @param display
	 * @param cellSize
	 * @return {@link Image}
	 * @throws Exception
	 */
	public static Image get_Image_From_Map_Board(Map_Board mapBoard, Display display, int cellSize) throws Exception
	{
		Image image = new Image(display, mapBoard.getColumns() * cellSize, mapBoard.getColumns() * cellSize);
		GC gc = new GC(image);
		
		int position_x = 0;
		int position_y = 0;
		Map_Cell mapCell = null;
		RGB rgb;
		
		for (int row = 0; row < mapBoard.getRows(); row++) 
		{
			for (int column = 0; column < mapBoard.getColumns(); column++) 
			{
				try {
					mapCell = mapBoard.get_Map_Cell(column, row);
				} catch (Exception e) {
					throw e;
				}
				
				rgb = get_RGB_From_Cell(mapCell);				
				position_x = column * cellSize;
				position_y = row * cellSize;
				
				gc.setBackground(
						Map_Colors.getColorFromRGB(rgb, display)
						);
			    gc.drawRectangle(position_x, position_y, cellSize, cellSize);

				
			}
		}
		
		return image;
	}
	
	
}
